// 解题思路：
// 这是一个典型的预处理问题，计算得分的时候不必每次都计算一下行和列的值
// 因为在计算同一行和列的得分的时候会有很多重复的计算
// 可以通过预处理的方式，计算每一行和每一列的得分
// 再根据每一个位置的坐标查表得到行和列的得分，求得改位置得得分

import java.util.*;
import java.io.*;

public class CrossExplosion {
    public static Read in = new Read();
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static void main(String[] args) throws IOException {
        int n = in.nextInt();
        int m = in.nextInt();
        int[][] arr = new int[n][m];
        long[] row = new long[n];
        long[] col = new long[m];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = in.nextInt();
                row[i] += arr[i][j];
                col[j] += arr[i][j];
            }
        }

        long[][] ret = new long[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                ret[i][j] = row[i] + col[j] - arr[i][j];
                out.print(ret[i][j] + " ");
            }
            out.println();
        }
        out.close();
    }
}

class Read{
    StringTokenizer st = new StringTokenizer("");
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

    String next() throws IOException{
        while(!st.hasMoreTokens()){
            st = new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException{
        return Integer.parseInt(next());
    }
}
